import upload from '@/utils/upload'
import request from '@/utils/request'

// 获取商品列表
export function getGoodsList(params) {
  return request({
    url: '/market/goods/catalog/list',
    method: 'get',
    params: params
  })
}

// 获取商品列表
export function getMyGoodsList(params) {
  return request({
    url: '/market/goods/my/list',
    method: 'get',
    params: params
  })
}

// 获取商品详情
export function getGoodsDetail(id) {
  return request({
    url: `/goods/${id}`,
    method: 'get'
  })
}

// 发布商品
export function publishGoods(data) {
  return request({
    url: '/market/goods',
    method: 'post',
    data: data
  })
}

// 更新商品
export function updateGoods(id, data) {
  return request({
    url: `/goods/${id}`,
    method: 'put',
    data: data
  })
}

// 删除商品
export function deleteGoods(id) {
  return request({
    url: `/goods/${id}`,
    method: 'delete'
  })
}

// 获取商品分类
export function getGoodsCategories() {
  return request({
    url: '/market/category/all/list',
    method: 'get'
  })
}

export function getGoodsCategoryTree() {
  return request({
    url: '/market/category/tree/list',
    method: 'get'
  })
}

// 上传商品图片
export function goodsUpload(file) {
  return upload({
    url: '/common/upload',
    method: 'post',
    filePath: file.path
  })
}